package cj.web.admin.dao;
/*
 *  
 *  
*/
import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.admin.domain.Game;

/**
 * 
 * @author 
 *
 */
@DAO
public interface GameDAO{
	
	@SQL("SELECT id,name,startDate,endDate,type,tel,price,duration,maxApplyCount,deleteFlag,createAt,createUser,updateAt,updateUser FROM Game WHERE deleteFlag=1 #if(:t.name!=''){ AND name LIKE '%##(:t.name)%' } ORDER BY updateAt DESC LIMIT :t.start,:t.length ")
    List<Game> query(@SQLParam("t") Game game);
	
	@SQL("SELECT id,name,startDate,endDate,type,tel,price,duration,maxApplyCount,deleteFlag,createAt,createUser,updateAt,updateUser FROM Game WHERE deleteFlag=1 ORDER BY updateAt DESC ")
    List<Game> queryAll();
	
	@SQL("SELECT count(1) FROM Game WHERE deleteFlag=1 #if(:t.name!=''){ AND name LIKE '%##(:t.name)%' } ")
    int querysize(@SQLParam("t") Game game);
    
    @SQL("SELECT * FROM Game WHERE id=:1")
    Game queryById(int id);
    
    @SQL("INSERT INTO Game (img,name,descs,startDate,endDate,type,tel,price,duration,maxApplyCount,deleteFlag,createAt,createUser,updateAt,updateUser) VALUES (:t.img,:t.name,:t.descs,:t.startDate,:t.endDate,:t.type,:t.tel,:t.price,:t.duration,:t.maxApplyCount,1,now(),:t.createUser,now(),:t.updateUser)")
    void create(@SQLParam("t") Game game);
	
	@SQL("UPDATE Game SET img=:t.img,name=:t.name,descs=:t.descs,startDate=:t.startDate,endDate=:t.endDate,type=:t.type,tel=:t.tel,price=:t.price,duration=:t.duration,maxApplyCount=:t.maxApplyCount,updateAt=now(),updateUser=:t.updateUser WHERE id=:t.id")
    void update(@SQLParam("t") Game game);
    
    @SQL("UPDATE Game SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
    
    @SQL("select id,name,price,duration from Game where deleteFlag=1 and NOW() BETWEEN startDate and DATE_ADD(endDate,INTERVAL 1 DAY)")
    List<Map> asGameEnum();
    
    @SQL("select id,name,price,duration from Game where deleteFlag=1 and type=:1 and NOW() BETWEEN startDate and DATE_ADD(endDate,INTERVAL 1 DAY)")
    List<Map> asGameEnum(int type);
}